<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleleaf.org">
<head th:insert="base">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="/back/admin/welcome">首页</a>
            <a href="#">投诉管理</a>
            <a>
              <cite>投诉列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <div class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" id="orderId"  placeholder="请输入订单id" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <select id="complaintType">
                            </select>
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <select id="handleStatus">
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" readonly  autocomplete="off" placeholder="投诉开始日期" id="createTimeStart">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" readonly  autocomplete="off" placeholder="投诉截止日期" id="createTimeEnd">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" id="formSearch"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-hide" id="tableId" lay-filter="tableId"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="operations">
    {{#if(d.handleStatus == '0'){}}
    <a class="layui-btn layui-btn-xs" lay-event="handle_pass" title="受理"><i class="layui-icon layui-icon-ok"></i>受理</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="handle_reject" title="不受理"><i class="layui-icon layui-icon-close"></i>不受理</a>
    {{#}}}
</script>
<script th:inline="none">
    layui.use(['table','form','util','tool','laydate','enums'], function(){
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var util = layui.util;
        var tool = layui.tool;
        var laydate = layui.laydate;
        var enums = layui.enums;
        var baseUrl = "/back/orderComplaint";
        init_form();
        table.render({
            elem: '#tableId'
            ,id:'tableReload'
            ,url: baseUrl + '/getList'
            ,limit:10
            ,limits:[10,20,50]
            ,method:'post'
            ,toolbar:'#toolbar'
            ,defaultToolbar: ['print']
            ,title: '投诉列表'
            ,cols: [[
                {field: '', title: '序号',width:50,type:'numbers'}
                ,{field:'orderId', title:'订单id',type: 'text',width:300}
                ,{field:'complaintUserName', title:'投诉人姓名',type: 'text',width:200}
                ,{field:'complaintTypeDesc', title:'投诉类别',type: 'text',width:120}
                ,{field:'handleStatusDesc', title:'受理状态',type: 'text',width:120}
                ,{field:'complaintContent', title:'投诉内容',type: 'text',width:400}
                ,{field:'createTime', title:'投诉时间',type: 'text',width:160,templet:function (d) {
                        if(d.createTime){
                            return util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss")
                        }
                        return "";
                    }}
                ,{title:'操作', toolbar: '#operations',width:300}
            ]]
            ,page: true
        });
        //行工具栏事件
        table.on('tool(tableId)', function(obj){
            var data = obj.data;
            switch (obj.event) {
                case 'handle_pass':
                    layer.confirm('确认受理该投诉？', function(index){
                        var res = tool.submit(baseUrl + '/handle',{id:data.id,handleStatus:'1'});
                        if(res.code == return_200){
                            layer.msg(res.msg, {
                                    icon: msg.success,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }else {
                            layer.msg(res.msg, {
                                    icon: msg.error,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }
                    });
                    break;
                case 'handle_reject':
                    layer.confirm('确认不受理该投诉？', function(index){
                        var res = tool.submit(baseUrl + '/handle',{id:data.id,handleStatus:'2'});
                        if(res.code == return_200){
                            layer.msg(res.msg, {
                                    icon: msg.success,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }else {
                            layer.msg(res.msg, {
                                    icon: msg.error,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }
                    });
                    break;
            }
        });
        //条件查询
        $('#formSearch').on('click', function(){
            table.reload('tableReload', {
                page: {curr: 1 }
                ,where:  getQueryParams()
            });
        });

        /**
         * 查询的参数
         * @returns {{}}
         */
        function getQueryParams() {
            return {
                orderId:$("#orderId").val().trim()
                ,complaintType:$("#complaintType").val().trim()
                ,handleStatus:$("#handleStatus").val().trim()
                ,createTimeStart:$("#createTimeStart").val().trim()
                ,createTimeEnd:$("#createTimeEnd").val().trim()
            }
        }

        /**
         * 初始化页面
         */
        function init_form() {
            enums.createSelectByEnum('complaintType','EnumComplaintType',null,null,'请选择投诉类别');
            enums.createSelectByEnum('handleStatus','EnumHandleStatus',null,null,'请选择受理状态');
            form.render();
            laydate.render({
                elem: '#createTimeStart'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#createTimeEnd'
                ,type: 'datetime'
            });
        }
        /**
         * 回调函数
         */
        function callBack() {
            $("#formSearch").click();
        }

    });
</script>
</body>
</html>